// 动态导入当前文件夹下的所有.vue后缀名的组件
const globalComponents: { [name: string]: object } = import.meta.glob(
  "./**/*.vue",
);
// 拆解组件名的函数
const getName = (path: string): string => {
  const pathSplit = path.split("/");
  const lastSplit = pathSplit[pathSplit.length - 1];
  const name =
    lastSplit.split(".")[0] !== "index"
      ? lastSplit.split(".")[0]
      : pathSplit[pathSplit.length - 2];
  return name;
};
export default {
  install(app: any) {
    Object.keys(globalComponents).forEach((key) => {
      const name = getName(key);
      app.component(name, globalComponents[key]);
    });
  },
};
